package com.leadership.training.entity.project;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.demo2do.core.format.PersistentFormat;
import com.leadership.training.entity.course.Course;
import com.leadership.training.entity.trainee.Trainee;

@Entity
@Table(name = "t_course_trainee_stat")
public class CourseTraineeStat {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @PersistentFormat
    private Trainee trainee;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @PersistentFormat
    private Course course;
    
    private int count;
    
    @Column(name = "is_disabled")
    private boolean disabled;

    /**
     * the default constructor
     */
    public CourseTraineeStat() {
    }

    public CourseTraineeStat(Trainee trainee, Course course) {
        this.trainee = trainee;
        this.course = course;
        this.count = 1;
        this.disabled = false;
    }
    
    /**
     * @return
     */
    public CourseTraineeStat autoCount(int count) {
        this.count = count++;
        return this;
    }
    
    /**
     * 
     * @param count
     * @return
     */
    public CourseTraineeStat deCount() {
        this.count = count--;
        if(count < 0) {
            count = 0;
        }
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the trainee
     */
    public Trainee getTrainee() {
        return trainee;
    }

    /**
     * @return the course
     */
    public Course getCourse() {
        return course;
    }

    /**
     * @return the count
     */
    public int getCount() {
        return count;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param trainee the trainee to set
     */
    public void setTrainee(Trainee trainee) {
        this.trainee = trainee;
    }

    /**
     * @param course the course to set
     */
    public void setCourse(Course course) {
        this.course = course;
    }

    /**
     * @param count the count to set
     */
    public void setCount(int count) {
        this.count = count;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
